import os

import pygame

import globalvars
import statpaneltext


class Panel(pygame.sprite.Sprite):
    def __init__(self, panelType, panelImage):
        pygame.sprite.Sprite.__init__(self) # Initialize base class
        self.spriteFile = os.path.join('data', panelImage)
        self.orgImage = pygame.image.load(self.spriteFile).convert_alpha()
        self.panelType = panelType
        self.lastNumber = 0.0
        self.panelFont = pygame.font.SysFont("Arial", 20)
        self.update()
    
    def update(self):
        if self.lastNumber != globalvars.number_of_tuxs:
            self.image = self.orgImage.copy()
            self.text = self.panelFont.render("%i" %(globalvars.number_of_tuxs), True, [0, 0, 0])
            self.image.blit(self.text, [550, 5])
            self.lastNumber = globalvars.number_of_tuxs
        self.rect = self.image.get_rect()

    def add_text(self):
        if self.panelType == "main":
            buildmenu = statpaneltext.StatPanelText("Build", [10, 5])
            globalvars.objects_panel_draw.add(buildmenu)
            
